//获取个人信息
function getSellerInfo() {
    function doCallBack(res) {
        if (res.retcode == 0) {
            var result = JSON.parse(Base64.decode(res.data));
            console.log(result);
            if (result) {

                $("#companyName").val(result.company_name);
                $("#username").val(result.real_name);
                $("#sex span").text(result.sex);
                if (result.sex == "男") {
                    $("#sex")
                        .addClass("male")
                        .removeClass("famale");
                } else {
                    $("#sex")
                        .addClass("famale")
                        .removeClass("male");
                }
                $("#telNumber").val(result.contact_mobile);
                $('#idNumber').val(result.id_number);
                $("#address").val(result.company_address);
               $('#companyName').val(result.company_name);
               $('#companyTel').val(result.company_telephone);
            } 
        }
       
    }
    $('#submitBtn').css({
        "display": "block"
    });
    jAjax("account.getdetails", doCallBack, {});
}
getSellerInfo();

//性别切换按钮的显示
$("#sex").click(function () {
    if ($(this).hasClass("famale")) {
        $(this)
            .addClass("male")
            .removeClass("famale");
        $(this)
            .children("span")
            .text("男");
    } else {
        $(this)
            .addClass("famale")
            .removeClass("male");
        $(this)
            .children("span")
            .text("女");
    }
});
$(".submitBtn").click(function () {
    var username = $("#username").val();
    var telNumber = $("#telNumber").val();
    var idNumber = $("#idNumber").val();
    var companyName = $("#companyName").val();
    var address = $("#address").val();
    var companyTel = $("#companyTel").val();
    var sex = $("#sex").val();
    //   if (username == "") {
    //     DoAlert("姓名不能为空");
    //     return false;
    //   } else if (telNumber == "" || !/^1\d{10}$/.test(telNumber)) {
    //       DoAlert("请输入正确的手机号码");
    //       return false;
    //   } else if (idNumber=="" || !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idNumber)) {
    //       DoAlert("请输入正确的身份证号码");
    //       return false;
    //   } else if (companyName == "") {
    //     DoAlert("公司名称不能为空");
    //     return false;
    //   } else if (address == "") {
    //       DoAlert("请填写正确的公司地址");
    //       return false;
    //   } else if (companyTel == "") {
    //     DoAlert("公司电话不能为空");
    //     return false;
    //   } else if (address == "") {
    //     DoAlert("请填写正确的公司地址");
    //     return false;
    //   }
    if (telNumber != "" && !/^1\d{10}$/.test(telNumber)) {
        DoAlert("请输入正确的手机号码");
        return false;
    } else if (idNumber != "" && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idNumber)) {
        DoAlert("请输入正确的身份证号码");
        return false;
        /^([0-9]{3,4}-)?[0-9]{7,8}$/
    } else if (companyTel != "" 		
		&& !/(^(4|8)00[0-9]{7}$)|(^(4|8)00-\d{3}-\d{4}$)|(^(4|8)00\d{1}-\d{3}-\d{3}$)|(^(4|8)00-\d{4}-\d{3}$)/.test(companyTel)
		//&& !/^800[0-9]{7}$/.test(companyTel)
		&& !/^1(2|3|4|5|6|7|8)([0-9]{9})$/.test(companyTel)
		&& !/^(0[0-9]{2,3})[0-9]{6,8}$/.test(companyTel)
		&& !/^(0[0-9]{2,3}-)[0-9]{6,8}$/.test(companyTel)
		
		//&& !/^([0-9]{3,4}-)?[0-9]{7,8}$/.test(companyTel)
		
	) {
        DoAlert("公司电话为：400、800或区号+座机号码");
        return false;
        
    } else {
        //调用卖家填写资料接口
        var sval = {
            company_name: companyName,
            real_name: username,
            contact_mobile: telNumber,
            //sex: sex,
            id_number: idNumber,
            company_telephone: companyTel,
            company_address: address
        };

        function doCallBack(res) {
            console.log(res);
            // DoAlert(res.message);
            if (res.retcode == 0) {
                DoAlert('提交成功');
            } else {
                DoAlert(res.message);
            }
        }
        jAjax("account.writedetails", doCallBack, sval);
    }
});

//解决键盘遮挡
resolveInput('#address');
resolveInput('#companyTel');